package cn.nexd.location.indoor.bean;

import java.util.ArrayList;
import java.util.List;

import cn.nexd.collector.bean.BeaconScannerResult;
import cn.nexd.collector.bean.MixCollectorResult;
import cn.nexd.collector.bean.WifiCollectorResult;

/**
 * Created by codngfish on 16/5/24.
 */
public class IndoorLocationDataStory {

    private List<IndoorLocationData> indoorLocationDatas;

    public IndoorLocationDataStory() {
        indoorLocationDatas = new ArrayList<>();
    }

    public synchronized void add(IndoorLocationData indoorLocationData) {
        indoorLocationDatas.add(indoorLocationData);
    }

    public synchronized void addWifiCollectorResults(List<WifiCollectorResult> wifiCollectorResults) {
        for (WifiCollectorResult wifiCollectorResult : wifiCollectorResults) {
            indoorLocationDatas.add(new IndoorLocationData(wifiCollectorResult.getRssi(), wifiCollectorResult.getWifiAddress()));
        }
    }

    public synchronized void addBeaconCollectorResults(List<BeaconScannerResult> beaconScannerResults) {
        for (BeaconScannerResult beaconScannerResult : beaconScannerResults) {
            indoorLocationDatas.add(new IndoorLocationData(beaconScannerResult.getRssi(), beaconScannerResult.getBeaconAddress()));
        }
    }

    public synchronized void addMixCollectorResults(List<MixCollectorResult> mixCollectorResults) {
        for (MixCollectorResult mixCollectorResult : mixCollectorResults) {
            indoorLocationDatas.add(new IndoorLocationData(mixCollectorResult.getLevel(), mixCollectorResult.getMac()));
        }
    }

    public synchronized List<IndoorLocationData> getIndoorLocationDatas() {
        List<IndoorLocationData> indoorLocationDataList = new ArrayList<>();
        indoorLocationDataList.addAll(indoorLocationDatas);
        indoorLocationDatas.clear();
        return indoorLocationDataList;
    }
}
